<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="libman.css">
<TITLE>
Invariants
</TITLE>
</HEAD>
<BODY >
<A HREF="libman068.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="libman064.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="libman070.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H2 CLASS="section"><A NAME="htoc153">10.5</A>&nbsp;&nbsp;Invariants</H2>

For writing sophisticated search algorithms it is useful to be able
not only to detect conflicts caused by tentative value changes,
but also to compute consequences of these changes.
For example, it is possible to repair certain constraints automatically
by (re)computing one or more of their variable's tentative values
based on the others (e.g. a sum constraint can be repaired by updating
the tentative value of the sum variable whenever the tentative value of one of
the other variables changes).
We provide two predicates for this purpose: <BR>
<BR>

<H4 CLASS="subsubsection">-Result tent_is +Expression</H4>
<A NAME="@default394"></A>
This is similar to the normal arithmetic
<A HREF="../bips/kernel/arithmetic/is-2.html"><B>is/2</B></A><A NAME="@default395"></A>
predicate, but evaluates the expression based on the tentative
assignment of its variables. The result is delivered as (an update to)
the tentative value of the Result variable.
Once initiated, <B>tent_is</B> will stay active and keep updating Result's
tentative value eagerly whenever the tentative assignment of any
variable in Expression changes.<BR>
<BR>

<H4 CLASS="subsubsection">tent_call(In, Out, Goal)</H4>
<A NAME="@default396"></A>
This is a completely general meta-predicate to support computations
with tentative values. Goal is a general goal, and In and Out are
lists (or other terms) containing subsets of Goal's variables.
A copy of Goal is called, with the In-variables replaced by their
tentative values and the Out-variables replaced by fresh variables.
Goal is expected to return values for the Out variables. These values
are then used to update the tentative values of the original Out variables.
This process repeats whenever the tentative value of any In-variable
changes.<BR>
<BR>

<H4 CLASS="subsubsection">Waking on Tentative Assignment Change</H4>
The predicates <A HREF="../bips/lib/repair/tent_is-2.html"><B>tent_is/2</B></A><A NAME="@default397"></A> and <A HREF="../bips/lib/repair/tent_call-3.html"><B>tent_call/3</B></A><A NAME="@default398"></A> are implemented
<A NAME="@default399"></A>
using the <B>ga_chg</B> suspension list which is attached to every
repair variable. The programmer has therefore all the tools to write
specialised, efficient versions of tent_call/3.
Follow the following pattern:
<BLOCKQUOTE CLASS="quote"> <PRE CLASS="verbatim">
my_invariant(In, Out) :-
        In tent_get TentIn,
        ... compute TentOut from TentIn ...
        suspend(my_invariant(In,Out,Susp), 3, [In-&gt;ga_chg]),
        Out tent_set TentOut.
</PRE></BLOCKQUOTE>
This can be made more efficient by using a demon (<A HREF="../bips/kernel/compiler/demon-1.html"><B>demon/1</B></A><A NAME="@default400"></A>).<BR>
<BR>
<HR>
<A HREF="libman068.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="libman064.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="libman070.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
